home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OWLSRC.PAK / SWINDOW.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  5.1 KB  |  224 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1991, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.7  $
  6. //
  7. // Streamable object implementation for TWindow.
  8. //----------------------------------------------------------------------------
  9. #include <owl/pch.h>
  10. #if !defined(OWL_APPLICAT_H)
  11. # include <owl/applicat.h>
  12. #endif
  13. #if !defined(OWL_APPDICT_H)
  14. # include <owl/appdict.h>
  15. #endif
  16. #if !defined(OWL_WINDOW_H)
  17. # include <owl/window.h>
  18. #endif
  19. #if !defined(OWL_SCROLLER_H)
  20. # include <owl/scroller.h>
  21. #endif
  22.  
  23. OWL_DIAGINFO;
  24.  
  25. //
  26. // Externs defined in owl.cpp
  27. //
  28. extern WNDPROC CreateInstanceThunk(TWindow*, TThunkProc);
  29.  
  30. IMPLEMENT_STREAMABLE(TWindow);
  31.  
  32. const int StreamIsTop      = 1;
  33. const int StreamIsTopChild = 2;
  34.  
  35. #if !defined(BI_NO_OBJ_STREAMING)
  36.  
  37. //
  38. //
  39. //
  40. void *
  41. TWindow::Streamer::Read(ipstream& is, uint32 version) const
  42. {
  43.   TWindow* o = GetObject();
  44.   int flags;
  45.   is >> flags;
  46.   if (flags & StreamIsTop) {
  47.     o->ChildList = 0;   // indicate no children connected yet
  48.     return o;           // we only need to read our child list
  49.   }
  50.  
  51.   o->Handle = 0;
  52.   o->Parent = 0;
  53.   o->SiblingList = 0;
  54.   o->ChildList = 0;
  55.   o->TransferBuffer = 0;
  56.   o->DefaultProc = 0;
  57.   o->HAccel = 0;
  58.   o->ContextPopupMenu = 0;
  59.   o->SetUniqueId();
  60.  
  61.   is >> o->Module;
  62.   TResId TempId;
  63.   is >> TempId;
  64.   o->Title = TempId;
  65.   is >> o->Flags;
  66.  
  67.   if (o->IsFlagSet(wfFromResource)) {
  68.     o->DefaultProc = (WNDPROC)::DefWindowProc;
  69.     memset(&o->Attr, 0, sizeof(o->Attr));
  70.   }
  71.   else {
  72.     long  temp;
  73.     is >> o->Attr.Style >> o->Attr.ExStyle >>
  74.           o->Attr.X >> o->Attr.Y >> o->Attr.W >> o->Attr.H >> temp;
  75.     o->Attr.Param = (char far*)temp;
  76.  
  77.     o->DefaultProc = (WNDPROC)::DefWindowProc;
  78.   }
  79.  
  80.   is >> o->Attr.Id
  81.      >> o->Attr.Menu
  82.      >> o->Attr.AccelTable;
  83.  
  84.   is >> o->ZOrder;
  85.  
  86.   is >> o->Parent;
  87.  
  88.   if (o->Parent) {
  89.     o->Application = o->Parent->GetApplication();
  90.  
  91.     // Version 1 and version 3 sibling streaming techniques
  92.     //
  93.     if (version == 1) {
  94.       if (flags & StreamIsTopChild)
  95.         o->Parent->ChildList = o;  // set parent's child pointer to this
  96.  
  97.       is >> o->ChildList;
  98.       is >> o->SiblingList;
  99.     }
  100.     else {
  101.       o->Parent->AddChild(o);
  102.  
  103.       static bool readSiblings = true;
  104.       bool saveReadSiblings = readSiblings;
  105.       readSiblings = true;
  106.       is >> o->ChildList;
  107.       readSiblings = saveReadSiblings;
  108.  
  109.       if (readSiblings) {
  110.         readSiblings = false;
  111.  
  112.         unsigned numSiblings;
  113.         is >> numSiblings;
  114.         for (unsigned i = 0; i < numSiblings; i++) {
  115.           TWindow* sibling;
  116.           is >> sibling;
  117.         }
  118.         readSiblings = true;
  119.       }
  120.     }
  121.   }
  122.   else {
  123.     o->Application = TYPESAFE_DOWNCAST(o->Module,TApplication);
  124.     if (!o->Application)
  125.       o->Application = ::GetApplicationObject();
  126.   }
  127.  
  128.   is >> o->Scroller;
  129.   if (o->Scroller)
  130.     o->Scroller->SetWindow(o);
  131.  
  132.   o->HCursor = 0;
  133.   is >> o->CursorModule >> o->CursorResId;
  134.   o->SetCursor(o->CursorModule, o->CursorResId);
  135.   is >> o->BkgndColor;  
  136.  
  137.   o->Thunk = CreateInstanceThunk(o, StdWndProc);
  138.  
  139.   return o;
  140. }
  141.  
  142. //
  143. //
  144. //
  145. void
  146. TWindow::Streamer::Write(opstream& os) const
  147. {
  148.   TWindow* o = GetObject();
  149.  
  150.   o->AssignZOrder();
  151.   int flags = 0;
  152.   if (o->IsFlagSet(wfStreamTop) || o->IsFlagSet(wfMainWindow))
  153.     flags |= StreamIsTop;
  154.   else if (o->Parent) {
  155.     if ((o->Parent->IsFlagSet(wfStreamTop) || o->Parent->IsFlagSet(wfMainWindow))
  156.       && o->Parent->ChildList == o)
  157.     flags |= StreamIsTopChild;
  158.   }
  159.   os << flags;
  160.  
  161.   if (flags & StreamIsTop)
  162.     return;
  163.  
  164.   os << o->Module;
  165.   os << TResId(o->Title);
  166.  
  167.   uint32 saveFlags = o->Flags;
  168.   if (o->GetHandle())
  169.     saveFlags |= wfAutoCreate;
  170.   os << saveFlags;
  171.  
  172.   if (!o->IsFlagSet(wfFromResource)) {
  173.     uint32 saveStyle = o->Attr.Style &
  174.                       ~(WS_MINIMIZE | WS_MAXIMIZE | WS_DISABLED | WS_VISIBLE);
  175.  
  176.     if (o->GetHandle())
  177.       saveStyle |= o->GetWindowLong(GWL_STYLE) &
  178.                    (WS_MINIMIZE | WS_MAXIMIZE | WS_DISABLED | WS_VISIBLE);
  179.  
  180.     os << saveStyle << o->Attr.ExStyle <<
  181.           o->Attr.X << o->Attr.Y << o->Attr.W << o->Attr.H <<
  182.           long(o->Attr.Param);
  183.   }
  184.  
  185.   os << o->Attr.Id
  186.      << o->Attr.Menu
  187.      << o->Attr.AccelTable;
  188.  
  189.   os << o->ZOrder;
  190.  
  191.   os << o->Parent;
  192.  
  193. #if 0  // (TWindow::Streamer::ClassVersion() == 1)
  194.   os << o->ChildList;
  195.   os << o->SiblingList;
  196.  
  197. #else  // version >= 3
  198.   if (o->Parent) {
  199.     static bool writeSiblings = true;
  200.     bool saveWriteSiblings = writeSiblings;
  201.     writeSiblings = true;
  202.     os << o->ChildList;
  203.     writeSiblings = saveWriteSiblings;
  204.  
  205.     if (writeSiblings) {
  206.       writeSiblings = false;
  207.  
  208.       os << (o->Parent->NumChildren()-1);
  209.       for (TWindow* sibling = o->SiblingList; sibling != o; sibling = sibling->Next())
  210.         os << sibling;
  211.       writeSiblings = true;
  212.     }
  213.   }
  214.  
  215. #endif
  216.  
  217.   os << o->Scroller;
  218.  
  219.   os << o->CursorModule << o->CursorResId;
  220.   os << o->BkgndColor;
  221. }
  222.  
  223. #endif  // if !defined(BI_NO_OBJ_STREAMING)
  224.